package com.handydata.antifraud.web;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;

import com.handydata.common.convert.CommonBeanConvertor;
import com.handydata.common.web.AbsController;

import com.handydata.antifraud.common.exception.AppTypeBasedataExCode;
import com.handydata.antifraud.bo.apptypebasedata.AppTypeBasedataReqBO;
import com.handydata.antifraud.bo.apptypebasedata.AppTypeBasedataResBO;
import com.handydata.antifraud.vo.apptypebasedata.CreateAppTypeBasedataReqVO;
import com.handydata.antifraud.vo.apptypebasedata.CreateAppTypeBasedataResVO;
import com.handydata.antifraud.vo.apptypebasedata.DeleteAppTypeBasedataReqVO;
import com.handydata.antifraud.vo.apptypebasedata.DeleteAppTypeBasedataResVO;
import com.handydata.antifraud.vo.apptypebasedata.ModifyAppTypeBasedataReqVO;
import com.handydata.antifraud.vo.apptypebasedata.ModifyAppTypeBasedataResVO;
import com.handydata.antifraud.vo.apptypebasedata.AppTypeBasedataBeanVO;
import com.handydata.antifraud.vo.apptypebasedata.QueryAppTypeBasedataReqVO;
import com.handydata.antifraud.vo.apptypebasedata.QueryAppTypeBasedataResVO;
import com.handydata.antifraud.service.AppTypeBasedataService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RequestMapping("/apptypebasedata")
@RestController
public class AppTypeBasedataController extends AbsController {
	
	private static final Logger logger = LoggerFactory.getLogger(AppTypeBasedataController.class);
	
	@Autowired
	private AppTypeBasedataService appTypeBasedataService;
	
	@ApiOperation(value="新增app分类码表", notes="新增app分类码表")
	@ApiImplicitParam(name = "req", value = "新增app分类码表请求对象", required = true, dataType = "CreateAppTypeBasedataReqVO", paramType = "body")
	@PostMapping("/create")
	public CreateAppTypeBasedataResVO createAppTypeBasedata(@RequestBody CreateAppTypeBasedataReqVO req) {
		try {
			logger.info("Execute createAppTypeBasedata, param is {}", req);
			AppTypeBasedataReqBO reqBO = CommonBeanConvertor.convert(req, AppTypeBasedataReqBO.class);
			AppTypeBasedataResBO resBO = appTypeBasedataService.createAppTypeBasedata(reqBO);
			CreateAppTypeBasedataResVO res = CommonBeanConvertor.convert(resBO, CreateAppTypeBasedataResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, CreateAppTypeBasedataResVO.class, req, AppTypeBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}

	@ApiOperation(value="修改app分类码表", notes="修改app分类码表")
	@ApiImplicitParam(name = "req", value = "修改app分类码表请求对象", required = true, dataType = "ModifyAppTypeBasedataReqVO", paramType = "body")
	@PostMapping("/modify")
	public ModifyAppTypeBasedataResVO modifyAppTypeBasedata(@RequestBody ModifyAppTypeBasedataReqVO req) {
		try {
			logger.info("Execute modifyAppTypeBasedata, param is {}", req);
			AppTypeBasedataReqBO reqBO = CommonBeanConvertor.convert(req, AppTypeBasedataReqBO.class);
			AppTypeBasedataResBO resBO = appTypeBasedataService.modifyAppTypeBasedata(reqBO);
			ModifyAppTypeBasedataResVO res = CommonBeanConvertor.convert(resBO, ModifyAppTypeBasedataResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, ModifyAppTypeBasedataResVO.class, req, AppTypeBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}

	@ApiOperation(value="删除app分类码表", notes="删除app分类码表")
	@ApiImplicitParam(name = "req", value = "修改app分类码表请求对象", required = true, dataType = "DeleteAppTypeBasedataReqVO", paramType = "body")
	@PostMapping("/remove")
	public DeleteAppTypeBasedataResVO deleteAppTypeBasedata(@RequestBody DeleteAppTypeBasedataReqVO req) {
		try {
			logger.info("Execute deleteAppTypeBasedata, param is {}", req);
			AppTypeBasedataReqBO reqBO = CommonBeanConvertor.convert(req, AppTypeBasedataReqBO.class);
			AppTypeBasedataResBO resBO = appTypeBasedataService.deleteAppTypeBasedata(reqBO);
			DeleteAppTypeBasedataResVO res = CommonBeanConvertor.convert(resBO, DeleteAppTypeBasedataResVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, DeleteAppTypeBasedataResVO.class, req, AppTypeBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}
	
	@ApiOperation(value="查询app分类码表", notes="查询app分类码表")
	@ApiImplicitParam(name = "req", value = "查询app分类码表请求对象", required = true, dataType = "QueryAppTypeBasedataReqVO", paramType = "body")
	@PostMapping("/query")
	public QueryAppTypeBasedataResVO queryAppTypeBasedata(@RequestBody QueryAppTypeBasedataReqVO req) {
		try {
			logger.info("Execute queryAppTypeBasedata, param is {}", req);
			AppTypeBasedataReqBO reqBO = CommonBeanConvertor.convert(req, AppTypeBasedataReqBO.class);
			AppTypeBasedataResBO resBO = appTypeBasedataService.queryAppTypeBasedata(reqBO);
			QueryAppTypeBasedataResVO res = CommonBeanConvertor.convert(resBO, QueryAppTypeBasedataResVO.class, AppTypeBasedataBeanVO.class);
			return res;
		} catch (Exception e) {
			return handleException(e, QueryAppTypeBasedataResVO.class, req, AppTypeBasedataExCode.SYS_UNKNOWN_ERROR);
		}
	}
	
}
